package mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import mvp.com.bbc.rcjavaretrofitdaggermvp.R;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.ActivityUtils;
import mvp.com.bbc.rcjavaretrofitdaggermvp.baseAF.BaseRefreshActivity;
import mvp.com.bbc.rcjavaretrofitdaggermvp.bean.InfoBean;
import mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.activity.CircleScaleLayoutActivity;
import mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.activity.GalleryLayoutActivity;
import mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.activity.TestAdapterActivity;
import mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.carousel.CarouselLayoutActivity;
import mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.circle.CircleLayoutActivity;

/**
 * Created by ${cbf} on 2017/11/24.
 */

public class InfoAdapter extends RecyclerView.Adapter<InfoAdapter.Vholder> {
    private List<InfoBean> infoBeen;
    private Context context;

    public InfoAdapter(Context context) {
        this.context = context;
        this.infoBeen = new ArrayList<>();
    }

    public void setData(List<InfoBean> data) {
        this.infoBeen = data;
        notifyDataSetChanged();
    }

    public void addData(List<InfoBean> infoBeens) {
        this.infoBeen.addAll(infoBeens);
        notifyDataSetChanged();
    }

    @Override
    public Vholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_info_list, parent, false);
        return new Vholder(view);
    }

    @Override
    public void onBindViewHolder(Vholder holder, final int position) {
        if (infoBeen != null && infoBeen.size() > 0) {
            InfoBean infoBean = infoBeen.get(position);
            holder.tvInfoConent.setText(infoBean.getContent());
            holder.tvInfoTime.setText(infoBean.getTime());
            if (infoBean.getReply().equals("")) {
                holder.tvInfoDes.setVisibility(View.GONE);
            } else {
                holder.tvInfoDes.setText(infoBean.getReply());
            }
            holder.tvInfoCount.setText(infoBean.getReplynum() + "个问答");
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position) {
                    case 0:
//                        ActivityUtils.skipActivity(ScaleLayoutActivity.class, null);
                        ActivityUtils.skipActivity(CarouselLayoutActivity.class, null);
                        break;
                    case 1:
                        ActivityUtils.skipActivity(CircleLayoutActivity.class, null);
//                        ActivityUtils.skipActivity(RotateLayoutActivity.class, null);
                        break;
                    case 2:
                        ActivityUtils.skipActivity(GalleryLayoutActivity.class, null);
                        break;
                    case 3:
                        ActivityUtils.skipActivity(CircleScaleLayoutActivity.class, null);
                    case 4:
                        ActivityUtils.skipActivity(BaseRefreshActivity.class, null);
                    case 5:
                        ActivityUtils.skipActivity(TestAdapterActivity.class, null);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return infoBeen.size();
    }

    public class Vholder extends RecyclerView.ViewHolder {

        private TextView tvInfoConent, tvInfoDes, tvInfoTime, tvInfoCount;

        public Vholder(View itemView) {
            super(itemView);
            tvInfoConent = (TextView) itemView.findViewById(R.id.tv_info_conent);
            tvInfoDes = (TextView) itemView.findViewById(R.id.tv_info_des);
            tvInfoTime = (TextView) itemView.findViewById(R.id.tv_info_time);
            tvInfoCount = (TextView) itemView.findViewById(R.id.tv_info_count);
        }
    }
}
